<!DOCTYPE html>
<html>
<head>
	<script type="text/javascript" src="__PUBLIC__/easyui/jquery.min.js"></script>
	<script type="text/javascript" src="__PUBLIC__/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="__PUBLIC__/easyui/locale/easyui-lang-zh_CN.js"></script>
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/easyui/themes/gray/easyui.css">
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/easyui/themes/icon.css">
	<script type="text/javascript" src="__PUBLIC__/js/easyuiValidatebox.js"></script>
</head>
<body>
<div>
	   <table id="frms" class="easyui-datagrid" style="width:auto;"  
        url="__URL__/positionData" rownumbers="true" pagination="true" toolbar="#tb" data-options="singleSelect:true,fitColumns:true" pageSize="20" pageList="[20,40,80]">  
        <thead>  
            <tr>  
                <th field="position_id" width="10" hidden="true">职位编号</th>  
                <th field="position_name" width="10%">职位名称</th>
                <th field="dpt_id" width="10" hidden="true">部门编号</th>
                <th field="dpt_name" width="10%">所属部门</th>
            </tr>
        </thead>  
    </table>  
    
        <div id="tb" style="padding:5px;height:auto"> 
            <div style="border-top:1px solid #ccc;border-bottom:1px solid #ccc;
                 font-size: 1.2em;margin-top:2px; margin-bottom: 2px;" align="center">
                快捷操作
            </div>
            <div style="">
                <a href="#" class="easyui-linkbutton" iconCls="icon-add"  onclick="add()">添加</a>   
                <a href="#" class="easyui-linkbutton" iconCls="icon-save"  onclick="edit()">修改</a> 
                <a href="#" class="easyui-linkbutton" iconCls="icon-remove"  onclick="del()">删除</a>
            </div>
        </div>    
</div>
    <div id="add_dlgs" class="easyui-dialog" style="width:280px;height:160px;"
            iconCls ="icon-mem-level"
			closed="true">
            <form method="post" id="afrms" >
                <table cellspacing="0" cellpadding="2" class='ftable'>
						
                    <tr style="line-height:45px;height: 45px">
                        <td width="100" align="right">职位名称：</td>
                        <td width="100">
                            <input type="text" id="position_name" class="easyui-validatebox" name="position_name" style="width:120px;" data-options="validType:['length[0,50]'],required:true"/> 
                        </td>
                    </tr>

                    <tr style="line-height:25px; height: 25px">
                        <td width="100" align="right">所属部门：</td>
                        <td width="100">
                            <select id="position_dpt_id" name="position_dpt_id">
                                    
                                    {$json}
                                </select>
                            
                        </td>
                    </tr>
                    <tr >
                        <td colspan="2" align='center'>
                        	<input type="submit" value="保存"/>
                            <input type="button" onClick="javascript:$('#add_dlgs').dialog('close')" value="取消" />
                        </td>
                    </tr>
                </table>
            </form>
   </div>
    <div id="edit_dlg" class="easyui-dialog" style="width:280px;height:160px;"
            iconCls ="icon-mem-level"
			closed="true">
            <form  method="post" id="efrms" >
                <table cellspacing="0" cellpadding="2" class='ftable'>
                	<input type="hidden" name="position_id"/>
                    <tr style="line-height:45px;height: 45px">
                        <td width="100" align="right">职位名称：</td>
                        <td width="100">
                            <input type="text" id="position_name" class="easyui-validatebox" name="position_name" style="width:120px;" data-options="validType:['length[0,50]'],required:true"/> 
                        </td>
                    </tr>

                    <tr style="line-height:25px; height: 25px">
                        <td width="100" align="right">所属部门：</td>
                        <td width="100">
                            <select id="position_dpt_id" name="position_dpt_id">
                             	{$json}
                            </select>
                        </td>
                    </tr>
                    
                    <tr>
                        <td colspan="2" align='center'>
                            <input type="submit" value="保存"/>
                            <input type="button" onClick="javascript:$('#edit_dlg').dialog('close')" value="取消" />
                            
                        </td>
                    </tr>
                </table>
            </form>
    </div>

<script type = "text/javascript">
       	//显示窗口
        function add()
        {
            $('#add_dlgs').dialog('open').dialog('setTitle','添加职位');
        };


        
        $(function(){
        	$('#afrms').form({
				url:'__URL__/addPositionPost',
			    onSubmit:function(){
			        return $(this).form('validate');
			    },
			    success:function(data){
			    	if(data=='ok'){
			    		$.messager.alert('提醒', '添加成功!', 'info');
			    		$('#frms').datagrid('reload');
                    	$('#add_dlgs').dialog('close');
			    	}
			    	if(data=='no'){
			    		$.messager.alert('提醒','添加失败!','info');
			    	}   
			    }
			});


			$('#efrms').form({
				url:'__URL__/editPositionPost',
			    onSubmit:function(){
			        return $(this).form('validate');
			    },
			    success:function(data){
			    	if(data=='ok'){
			    		$.messager.alert('提醒', '修改成功!', 'info');
			    		$('#frms').datagrid('reload');
                    	$('#edit_dlg').dialog('close');
			    	}
			    	if(data=='no'){
			    		$.messager.alert('提醒','修改失败!','info');
			    	}
			    }
			});
        })


        $('#frms').datagrid({
            onDblClickRow: function(rowIndex,rowData){
                $('#edit_dlg').dialog('open').dialog('setTitle','编辑职位');
                $('#efrms').form('clear');
                $('#efrms').form('load',rowData);
            }
        });

        function edit()
        {
            var row = $('#frms').datagrid('getSelected');
            
			if (row){
				$('#edit_dlg').dialog('open').dialog('setTitle','编辑职位');
                $('#efrms').form('clear');
				$('#efrms').form('load',row);
			}
            else {
                $.messager.alert('错误提示', "请选择一个职位", 'error');
            }
        }
        	

        function del()
        {
            var row = $('#frms').datagrid('getSelected');
            if (row) {
                $.messager.confirm('提示信息', '是否删除该职位？', function (r) {
                    if (r) {
                        $.ajax({
                            url: "__URL__/delPositionPost",
                            data: {position_id: row.position_id},
                            type:'post',
                            success: function (data) { 
                            	if(data=='ok'){
                            		$.messager.alert('提醒', '删除成功!', 'info');
                            		$('#frms').datagrid('reload');
                            	}
                            	if(data=='no'){
                            		$.messager.alert('提醒','修改失败!','info');
                            	}
                                
                            }

                        });
                    }
                });
            }
            else {
                $.messager.alert('错误提示', "请选择一个职位", 'error');
            }
        }
   
</script>
</body>
</html>